define(function(require, exports, module) {

	require("plugins/desktop/window-style.css");

	var menubar = require("plugins/desktop/window-menubar.js");
	var router = require("plugins/tools/router.js");
	var config = require("plugins/config/config.js");
	var index = require("index");

	module.exports = {

		render: function(data, fullscreen) {
			var dom = $('<div class="main-desktop">' +
				'<div class="sys-menu-right">' +
					'<i-button icon="md-swap" shape="circle" v-on:click="onSwitchDesktop"></i-button>' +
					'<i-button :icon="this.fullscreen ? \'md-contract\' : \'md-expand\'" shape="circle" v-on:click="onFullScreen"></i-button>' +
					'<i-button icon="ios-home" shape="circle" v-on:click="onHomeClick"></i-button>' +
					'<i-button shape="circle" icon="md-settings" v-on:click="profile" :title="index.profile"></i-button>' +
				    '<i-button shape="circle" type="error" icon="md-log-out" v-on:click="exit" :title="index.exit"></i-button>' +
				'</div>' +
			'</div>').appendTo(document.body);
			//更多功能路由
			router.addRouter("index/more");

			this.bindVue(dom, data, fullscreen);
		}, 
		bindVue:function(dom, data, fullscreen) {
			var home = null;
			var profile = null;
			var vue = new Vue({
				el:$("div.sys-menu-right").get(0),
				data:{
					fullscreen:fullscreen,
					index:{
						profile:$.i18n.prop("info.profile"),
						exit:$.i18n.prop("info.exit")
					}
				},
				methods:{
					
					onFullScreen:function() {
						if(this.fullscreen) {
							document.exitFullscreen?document.exitFullscreen():
							document.mozCancelFullScreen?document.mozCancelFullScreen():
							document.webkitExitFullscreen?document.webkitExitFullscreen():'';
						} else {
							var element = document.body;
	               			var requestMethod =element.requestFullScreen
					             ||element.webkitRequestFullScreen //谷歌
					             ||element.mozRequestFullScreen  //火狐
					             ||element.msRequestFullScreen; //IE11
					        if (requestMethod) {     
					            requestMethod.call(element);   
					        } else if (typeof window.ActiveXObject !== "undefined") {  
					            var wscript = new ActiveXObject("WScript.Shell"); 
					            if (wscript !== null) {    //创建成功
					                 wscript.SendKeys("{F11}");//触发f11   
					            }   
					        }
					    }
					    this.fullscreen = !this.fullscreen;
					},
					onSwitchDesktop:function() {
						//关闭所有窗口
						$.closeAllWindow();
						//切换为window类型
						$(dom).remove();
						this.$destroy();
						data.desktop = "normal";
						index.render(data, function() {}, this.fullscreen);
					},
					onHomeClick:function() {
						if(home == null) {
							home = $.window({
								title:$.i18n.prop("home.title"),
								router: "index/home",
								end:function() {
									home = null;
								}
							});
						} else {
							home.show();
						}
					},
					profile:function() {
						if(profile == null) {
							profile = $.window({
								title:$.i18n.prop("info.profile"),
								router:"index/profile",
								maxmin:false,
								max:false,
								resize:false,
								area:['500px', '400px'],
								end:function() {
									profile = null;
								}
							});
						} else {
							profile.show();
						}
					},
					exit:function() {
						$.confirm($.i18n.prop("info.confirm.exit"), function (isOk){
							if(isOk) {
								$.get(config.getLogoutLocation(), {}, function() {
									window.location.href = config.getLoginLocation();
								});
							}
						}, true);
					}
				},
				mounted:function() {
					//构建目录
					menubar.build(".main-desktop", data.menus);
				}
			});
			vue.onHomeClick();
		}

	}
});